<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="项目名">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目代号" prop="projectCode">
        <el-input
          v-model="queryParams.projectCode"
          placeholder="请输入项目代号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="票据号" prop="number">
        <el-input
          v-model="queryParams.number"
          placeholder="请输入票据号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--      <el-form-item label="状态" prop="status">-->
      <!--        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>-->
      <!--          <el-option-->
      <!--            v-for="dict in dict.type.purchase_status"-->
      <!--            :key="dict.value"-->
      <!--            :label="dict.label"-->
      <!--            :value="dict.value"-->
      <!--          />-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <el-form-item label="项目状态" prop="projectStatus">
        <el-select v-model="queryParams.projectStatus" placeholder="请选择项目状态" clearable>
          <el-option
            v-for="dict in dict.type.project_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['purchase:ryDepotHead:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-upload2"
          size="mini"
          :disabled="single || status != 0?true:false"
          @click="producePurchase"
          v-hasPermi="['purchase:ryDepotHead:edit']"
        >生成采购单
        </el-button>
      </el-col>

      <!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    </el-row>

    <el-table v-loading="loading" :data="ryDepotHeadList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column type="selection" width="55" align="center"/>-->
      <!--      <el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="项目名" align="center" prop="projectName"/>
      <el-table-column label="项目代号" align="center" prop="projectCode"/>
      <el-table-column label="票据号" align="center" prop="number"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="出入库时间" align="center" prop="operTime" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.operTime, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="操作员" align="center" prop="operName"/>
      <!--      <el-table-column label="状态" align="center" prop="status">-->
      <!--        <template slot-scope="scope">-->
      <!--          <dict-tag :options="dict.type.purchase_status" :value="scope.row.status"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="项目状态" align="center" prop="projectStatus">
        <template slot-scope="scope">
          <el-select v-model="scope.row.projectStatus" :value-key="scope.row.projectStatus"
                     @change="updateStatus(scope.row)"
          >
            <el-option
              v-for="dict in dict.type.project_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
          <!--                <span>{{scope.row.name}}</span>-->
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['purchase:ryDepotHead:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetails(scope.row)"
            v-hasPermi="['purchase:ryDepotHead:remove']"
          >详情
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-upload2"
            @click="producePurchase(scope.row)"
            v-hasPermi="['purchase:ryDepotHead:remove']"
            :disabled="scope.row.projectStatus!=0?true:false"
          >生成采购单
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改单据主表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px">
      <el-form ref="form" :model="form" :rules="rules" label-width="110px" :hide-required-asterisk="true">
        <el-row :gutter="10" class="mb8">
          <el-col :span="6">
            <el-form-item label="项目名" prop="projectName">
              <el-input v-model="form.projectName" placeholder="请输入项目名"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="项目代号" prop="projectCode">
              <el-input v-model="form.projectCode" placeholder="请输入项目代号"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="票据号" prop="number">
              <el-input v-model="form.number" placeholder="请输入票据号" :readonly="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="6" v-if="title !=='添加单据主表'">
            <el-form-item label="创建时间:">
              <span>{{ parseTime(form.createTime) }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10" class="mb8">
          <el-col :span="4" v-if="title ==='添加单据主表'">
            <el-form-item label="文件导入">
              <a-upload style="display: flex"
                        accept=".xls, .xlsx, .et"
                        @change="readExcel"
                        :showUploadList="false"
              >

                <el-tooltip v-show="fileNames.length>0" placement="top" effect="light">
                  <div slot="content" value="true">
                    <div v-for="(item,index) in fileNames" :key="index" >
                      <div >{{ item.name }}</div>
                    </div>
                  </div>
                  <a-button type="primary" icon="import" style="display: inline-block;margin-right: 10px">
                    导入</a-button>
                </el-tooltip>
                <a-button v-show="fileNames.length<=0" type="primary" icon="import" style="display: inline-block;margin-right: 10px">
                  导入</a-button>
              </a-upload>
            </el-form-item>
          </el-col>
          <el-col :span="6" v-if="title ==='添加单据主表'">
            <el-popover v-show="fileNames.length>0" placement="top" v-model="visible">
              <div style="font-weight: 600;margin-bottom: 20px">文件上传列表</div>
              <div v-for="(item,index) in fileNames" :key="index" style="padding-left: 20px;">
                <div >{{ item.name }}</div>
              </div>
              <div style="text-align: right; margin-top: 20px">
                <el-button size="mini" type="text" @click="visible = false">取消</el-button>
                <el-button type="primary" size="mini" @click="generate">确定</el-button>
              </div>
              <a-button slot="reference" type="primary" icon="el-icon-thumb">点击生成</a-button>
            </el-popover>
          </el-col>
        </el-row>
        <el-row :gutter="10" class="mb8">
          <el-button type="primary" @click="addRow()" style="margin-bottom: 10px">增加</el-button>
          <div style="width: 100%;overflow: auto hidden;text-align: center">
            <el-table
              :data="tableData"
              style="width: 100%"
              border
              max-height="450"
            >
              <!--            <el-table :data="tableData" border style="max-height:calc(450px - 48px)">-->
              <el-table-column label="物品名称" width="150" fixed>
                <template slot-scope="scope">
                  <el-input placeholder="请输入物品名称" v-model="scope.row.inventoryName">
                    <i slot="suffix" class="el-icon-search" @click="search(scope.row)" style="margin-top: 12px"></i>
                  </el-input>
                  <!--                  <span>{{scope.row.inventoryName}}</span>-->
                </template>
              </el-table-column>
              <el-table-column label="物品规格" fixed>
                <template slot-scope="scope">
                  <!--                <el-input placeholder="请输入物品规格" v-model="scope.row.inventorySpecifications"></el-input>-->
                  <span>{{ scope.row.inventorySpecifications }}</span>
                </template>
              </el-table-column>
              <el-table-column label="供应商">
                <template slot-scope="scope">
                  <el-input placeholder="请输入供应商" v-model="scope.row.supply"></el-input>
                  <!--                <span>{{scope.row.supply}}</span>-->
                </template>
              </el-table-column>
              <el-table-column label="wbs编码">
                <template slot-scope="scope">
                  <el-input placeholder="请输入wbs编码" v-model="scope.row.wbs"></el-input>
                  <!--                <span>{{scope.row.wbs}}</span>-->
                </template>
              </el-table-column>
              <el-table-column label="备注">
                <template slot-scope="scope">
                  <el-input placeholder="请输入备注" v-model="scope.row.remark"></el-input>
                  <!--                <span>{{scope.row.remark}}</span>-->
                </template>
              </el-table-column>
              <el-table-column prop="advancePurchaseNum" label="待采购数量"></el-table-column>
              <el-table-column label="总库可用数量">
                <template slot-scope="scope">
                  <!--                  <el-input placeholder="请输入备注" v-model="scope.row.advancePurchaseNum"></el-input>-->
                  <span>{{ scope.row.usableNum }}</span>
                </template>
              </el-table-column>
              <el-table-column label="单价">
                <template slot-scope="scope">
                  <!--                  <el-input placeholder="请输入备注" v-model="scope.row.advancePurchaseNum"></el-input>-->
                  <el-input class="unitPrice" v-model="scope.row.unitPrice" type="number" oninput="if(value<0)value=0"
                  ></el-input>
                </template>
              </el-table-column>
              <!--              <el-table-column label="实际采购数量">-->
              <!--                <template slot-scope="scope">-->
              <!--&lt;!&ndash;                  <el-input placeholder="请输入采购数量" v-model="scope.row.actualPurchaseNum"></el-input>&ndash;&gt;-->
              <!--                  &lt;!&ndash;                <span>{{scope.row.name}}</span>&ndash;&gt;-->
              <!--                  <el-input-number placeholder="请输入采购数量" v-model="scope.row.actualPurchaseNum" style="width: 50px;text-align: left;padding: 0px 0px"-->
              <!--                                   size="small" :controls="false"-->
              <!--                                   :max="scope.row.advancePurchaseNum === 0 ? 10000 : scope.row.advancePurchaseNum" :min="0"></el-input-number>-->
              <!--                </template>-->
              <!--              </el-table-column>-->
              <!--              <el-table-column label="发货状态">-->
              <!--                <template slot-scope="scope">-->
              <!--                  <el-select v-model="scope.row.shippingStatus" placeholder="请选择发货状态">-->
              <!--                    <el-option-->
              <!--                      v-for="dict in dict.type.shipping_status"-->
              <!--                      :key="dict.value"-->
              <!--                      :label="dict.label"-->
              <!--                      :value="dict.value"-->
              <!--                    ></el-option>-->
              <!--                  </el-select>-->
              <!--                  &lt;!&ndash;                <span>{{scope.row.name}}</span>&ndash;&gt;-->
              <!--                </template>-->
              <!--              </el-table-column>-->
              <!--              <el-table-column label="采购员">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.purchaseMan }}</span>-->
              <!--                </template>-->
              <!--              </el-table-column>-->
              <!--              <el-table-column label="合格数量">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.qualifiedNum }}</span>-->
              <!--                </template>-->
              <!--              </el-table-column>-->
              <!--              <el-table-column label="不合格数量">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入不合格数量" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.unqualifiedNum }}</span>-->
              <!--                </template>-->
              <!--              </el-table-column>-->
              <!--              <el-table-column label="不合格原因">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.unqualifiedReason }}</span>-->
              <!--                </template>-->
              <!--              </el-table-column>-->
              <!--              <el-table-column label="退回状态">-->
              <!--                <template slot-scope="scope">-->
              <!--                    <span v-for="(item) in dict.type.returnStatus" v-if="scope.row.returnStatus === item.value">-->
              <!--                    {{ item.label }}-->
              <!--                  </span>-->
              <!--                </template>-->
              <!--              </el-table-column>-->
              <!--              <el-table-column label="重发状态">-->
              <!--                <template slot-scope="scope">-->
              <!--                    <span v-for="(item) in dict.type.retransmission_status" v-if="scope.row.retransmissionStatus === item.value">-->
              <!--                    {{ item.label }}-->
              <!--                  </span>-->
              <!--                </template>-->
              <!--              </el-table-column>-->
              <!--              <el-table-column label="重发数量">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.retransmissionNum }}</span>-->
              <!--                </template>-->

              <!--              </el-table-column>-->
              <!--              <el-table-column label="质检员">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.qualityInspector }}</span>-->
              <!--                </template>-->

              <!--              </el-table-column>-->
              <!--              <el-table-column label="质检时间">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.qualityTime }}</span>-->
              <!--                </template>-->

              <!--              </el-table-column>-->
              <!--              <el-table-column label="入库数量">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.inNum }}</span>-->
              <!--                </template>-->

              <!--              </el-table-column>-->
              <!--              <el-table-column label="入库仓库">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.inDepot }}</span>-->
              <!--                </template>-->

              <!--              </el-table-column>-->
              <!--              <el-table-column label="库位">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.location }}</span>-->
              <!--                </template>-->

              <!--              </el-table-column>-->
              <!--              <el-table-column label="入库操作员">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.inOperateMan }}</span>-->
              <!--                </template>-->

              <!--              </el-table-column>-->
              <!--              <el-table-column label="入库时间">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.inTime }}</span>-->
              <!--                </template>-->

              <!--              </el-table-column>-->
              <!--              <el-table-column label="出库数量">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.outNum }}</span>-->
              <!--                </template>-->

              <!--              </el-table-column>-->
              <!--              <el-table-column label="出库仓库">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.outDepot }}</span>-->
              <!--                </template>-->

              <!--              </el-table-column>-->
              <!--              <el-table-column label="出库操作员">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.outOperateMan }}</span>-->
              <!--                </template>-->

              <!--              </el-table-column><el-table-column label="领用人">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.outOperateMan }}</span>-->
              <!--                </template>-->

              <!--              </el-table-column><el-table-column label="出库时间">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.outTime }}</span>-->
              <!--                </template>-->

              <!--              </el-table-column>-->
              <!--              <el-table-column label="转移数量">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                  <el-input placeholder="请输入备注" v-model="scope.row.advancePurchaseNum"></el-input>&ndash;&gt;-->
              <!--                  <span>{{scope.row.transferNum === '' ? 0 : scope.row.transferNum}}</span>-->
              <!--                </template>-->
              <!--              </el-table-column>-->
              <el-table-column label="操作" fixed="right">
                <template slot-scope="scope">
                  <el-popconfirm title="确定删除吗？" @confirm="deleteRow(scope)">
                    <el-button type="primary" slot="reference">删除</el-button>
                  </el-popconfirm>

                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-row>
        <el-form-item label="备注">
          <el-input v-model="form.remark"></el-input>
        </el-form-item>
        <el-form-item label="附件名称">
          <file-upload v-model="form.fileName"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
      <!--      物品列表-->
      <el-dialog
        width="65%"
        title="物品信息"
        :visible.sync="goodsDetailsStatus"

        append-to-body
      >
        <el-form :model="goodsQueryParams" size="small" label-width="100px">
          <el-row :gutter="10" class="mb8">
            <el-col :span="6">
              <el-form-item label="物品名称" prop="projectCode">
                <el-input
                  v-model="goodsQueryParams.name"
                  placeholder="请输入物品名称"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-button type="primary" icon="el-icon-search" size="mini" @click="goodsQuery">搜索</el-button>
            </el-col>
          </el-row>

        </el-form>

        <el-table v-loading="loading" max-height="450" :data="RyInventoryList">
          <!--      <el-table-column label="主键" align="center" prop="id" />-->
          <el-table-column label="名称" align="center" prop="name"/>
          <el-table-column label="规格" align="center" prop="specifications"/>
          <el-table-column label="wbs编码" align="center" prop="wbs"/>
          <el-table-column label="品牌" align="center" prop="brand"/>
          <el-table-column label="图片" align="center" prop="images" width="100">
            <template slot-scope="scope">
              <image-preview :src="scope.row.images" :width="50" :height="50"/>
            </template>
          </el-table-column>
          <el-table-column label="单位" align="center" prop="unit">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.ware_inventory_unit" :value="scope.row.unit"/>
            </template>
          </el-table-column>
          <el-table-column label="单价(元)" align="center" prop="unitPrice"/>
          <el-table-column label="供应商" align="center" prop="supply"/>
          <el-table-column label="库位" align="center" prop="location"/>
          <el-table-column label="操作人/经办人" align="center" prop="operator"/>
          <el-table-column label="备注" align="center" prop="remark"/>
          <el-table-column label="操作" fixed="right">
            <template slot-scope="scope">
              <el-button type="primary" @click="goodsChange(scope.row)">选中</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="goodsTotal>0"
          :total="goodsTotal"
          :page.sync="goodsQueryParams.pageNum"
          :limit.sync="goodsQueryParams.pageSize"
          @pagination="search(undefined)"
        />
      </el-dialog>
    </el-dialog>

    <!--    详情弹窗-->
    <el-dialog :title="title" :visible.sync="details" width="1200px">
      <el-form ref="form" :model="form" label-width="100px">
        <el-row :gutter="10" class="mb8">
          <el-col :span="6">
            <el-form-item label="项目名: ">
              <!--              <el-input v-model="form.projectName" placeholder="请输入项目名"/>-->
              <span>{{ form.projectName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="项目代号: " prop="projectCode">
              <!--              <el-input v-model="form.projectCode" placeholder="请输入项目代号"/>-->
              <span>{{ form.projectCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="票据号: " prop="number">
              <!--              <el-input v-model="form.number" placeholder="请输入票据号"/>-->
              <span>{{ form.number }}</span>

            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10" class="mb8" v-show="false">
          <div style="width: 100%;overflow-x: auto;text-align: center">
            <el-table :data="tableData" border max-height="450" ref="report-table">
              <el-table-column label="项目名称">
                <el-table-column prop="inventoryName" label="物品名称" width="150"></el-table-column>
                <el-table-column prop="inventorySpecifications" label="物品规格"></el-table-column>

              </el-table-column>

              <el-table-column :label="form.projectName">
                <el-table-column prop="supply" label="供应商"></el-table-column>
                <el-table-column prop="wbs" label="wbs编码"></el-table-column>

              </el-table-column>

              <el-table-column label="项目代号">
                <el-table-column prop="remark" label="备注"></el-table-column>


              </el-table-column>

              <el-table-column :label="form.projectCode">
                <el-table-column prop="advancePurchaseNum" label="待采购数量"></el-table-column>

              </el-table-column>


              <el-table-column label="票据号">
                <el-table-column prop="usableNum" label="总库可用数量"></el-table-column>

              </el-table-column>

              <el-table-column :label="form.number">
                <el-table-column prop="unitPrice" label="单价"></el-table-column>
              </el-table-column>

            </el-table>
          </div>
        </el-row>
        <el-row :gutter="10" class="mb8">
          <div style="width: 100%;overflow-x: auto;text-align: center">
            <el-table :data="tableData" border>
              <el-table-column prop="inventoryName" label="物品名称" width="150"></el-table-column>
              <el-table-column prop="inventorySpecifications" label="物品规格" width="150"></el-table-column>
              <el-table-column prop="supply" label="供应商"></el-table-column>
              <el-table-column prop="wbs" label="wbs编码"></el-table-column>
              <el-table-column prop="remark" label="备注"></el-table-column>
              <el-table-column prop="advancePurchaseNum" label="待采购数量"></el-table-column>
              <el-table-column prop="usableNum" label="总库可用数量"></el-table-column>
              <el-table-column prop="unitPrice" label="单价"></el-table-column>
            </el-table>
          </div>
        </el-row>
      </el-form>
      <div slot="footer" style="text-align: center">
        <el-button type="success" size="medium" @click="exportExcel">导出</el-button>
      </div>
    </el-dialog>

    <!-- 生成采购单对话框 -->
    <el-dialog title="生成采购单" :visible.sync="purchase" width="1200px">
      <el-form ref="form" :model="form" :rules="ruless" label-width="110px" :hide-required-asterisk="true">
        <el-row :gutter="10" class="mb8">
          <el-col :span="6">
            <el-form-item label="票据号">
              <el-input v-model="form.number" placeholder="请输入票据号" :readonly="true"/>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="采购合同编号" prop="contractNumber">
              <el-input v-model="form.contractNumber" placeholder="请输入采购合同编号"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="项目关联">
              <span>{{ form.projectName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="供应商" prop="organId">
              <el-select v-model="form.organId" clearable placeholder="请选择" @change="ab">
                <el-option
                  v-for="item in organOptions"
                  :key="item.id"
                  :label="item.companyName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="10" class="mb8">
          <div style="width: 100%;overflow: auto hidden;text-align: center;margin-bottom: 60px">
            <el-table
              :data="tableData"
              style="width: 100%"
              border
              max-height="450"
            >
              <!--            <el-table :data="tableData" border style="max-height:calc(450px - 48px)">-->
              <el-table-column label="物品名称" width="150" fixed>
                <template slot-scope="scope">
                  <el-input placeholder="请输入物品名称" v-model="scope.row.inventoryName">
                    <i slot="suffix" class="el-icon-search" @click="search(scope.row)" style="margin-top: 12px"></i>
                  </el-input>
                  <!--                  <span>{{scope.row.inventoryName}}</span>-->
                </template>
              </el-table-column>
              <el-table-column label="物品规格" fixed>
                <template slot-scope="scope">
                  <!--                <el-input placeholder="请输入物品规格" v-model="scope.row.inventorySpecifications"></el-input>-->
                  <span>{{ scope.row.inventorySpecifications }}</span>
                </template>
              </el-table-column>
              <el-table-column label="供应商">
                <template slot-scope="scope">
                  <el-input placeholder="请输入供应商" v-model="scope.row.supply"></el-input>
                  <!--                <span>{{scope.row.supply}}</span>-->
                </template>
              </el-table-column>
              <el-table-column label="wbs编码">
                <template slot-scope="scope">
                  <el-input placeholder="请输入wbs编码" v-model="scope.row.wbs"></el-input>
                  <!--                <span>{{scope.row.wbs}}</span>-->
                </template>
              </el-table-column>
              <el-table-column label="单价">
                <template slot-scope="scope">
                  <el-input placeholder="请输入单价" v-model="scope.row.unitPrice"></el-input>
                  <!--                <span>{{scope.row.wbs}}</span>-->
                </template>
              </el-table-column>
              <el-table-column label="备注">
                <template slot-scope="scope">
                  <el-input placeholder="请输入备注" v-model="scope.row.remark"></el-input>
                  <!--                <span>{{scope.row.remark}}</span>-->
                </template>
              </el-table-column>
              <el-table-column prop="advancePurchaseNum" label="待采购数量"></el-table-column>
              <el-table-column label="总库可用数量">
                <template slot-scope="scope">
                  <!--                  <el-input placeholder="请输入备注" v-model="scope.row.advancePurchaseNum"></el-input>-->
                  <span>{{ scope.row.usableNum }}</span>
                </template>
              </el-table-column>
              <el-table-column label="实际采购数量">
                <template slot-scope="scope">
                  <!--                  <el-input placeholder="请输入采购数量" v-model="scope.row.actualPurchaseNum"></el-input>-->
                  <!--                <span>{{scope.row.name}}</span>-->
                  <el-input-number placeholder="请输入采购数量" v-model="scope.row.actualPurchaseNum"
                                   style="width: 50px;text-align: left;padding: 0px 0px"
                                   size="small" :controls="false"
                                   :max="scope.row.advancePurchaseNum === 0 ? 10000 : scope.row.advancePurchaseNum"
                                   :min="0"
                  ></el-input-number>
                </template>
              </el-table-column>
<!--              <el-table-column label="发货状态">-->
<!--                <template slot-scope="scope">-->
<!--                  <el-select v-model="scope.row.shippingStatus" placeholder="请选择发货状态">-->
<!--                    <el-option-->
<!--                      v-for="dict in dict.type.shipping_status"-->
<!--                      :key="dict.value"-->
<!--                      :label="dict.label"-->
<!--                      :value="dict.value"-->
<!--                    ></el-option>-->
<!--                  </el-select>-->
<!--                  &lt;!&ndash;                <span>{{scope.row.name}}</span>&ndash;&gt;-->
<!--                </template>-->
<!--              </el-table-column>-->

              <el-table-column label="操作">
              </el-table-column>
            </el-table>
          </div>
          <!--          <div style="text-align: center;font-size: 20px;margin-bottom: 20px">关联项目</div>-->
          <!--          <div style="width: 100%;overflow: auto hidden;text-align: center">-->
          <!--            <el-table-->
          <!--              :data="projectTableData"-->
          <!--              style="width: 100%"-->
          <!--              border-->
          <!--              max-height="450"-->
          <!--            >-->
          <!--              <el-table-column prop="inventoryName" label="物品名称"  width="150" fixed></el-table-column>-->
          <!--              <el-table-column prop="inventorySpecifications" label="物品规格"  width="150" fixed></el-table-column>-->
          <!--              <el-table-column prop="supply" label="供应商"></el-table-column>-->
          <!--              <el-table-column prop="wbs" label="wbs编码"></el-table-column>-->
          <!--              <el-table-column prop="remark" label="备注"></el-table-column>-->
          <!--              <el-table-column prop="advancePurchaseNum" label="待采购数量"></el-table-column>-->
          <!--              <el-table-column prop="actualPurchaseNum" label="实际采购数量"></el-table-column>-->

          <!--              <el-table-column prop="shippingStatus" label="发货状态"></el-table-column>-->

          <!--              <el-table-column prop="purchaseMan" label="采购员"></el-table-column>-->
          <!--              <el-table-column prop="qualifiedNum" label="合格数量"></el-table-column>-->
          <!--              <el-table-column prop="unqualifiedNum" label="不合格数量"></el-table-column>-->
          <!--              <el-table-column prop="unqualifiedReason" label="不合格原因"></el-table-column>-->

          <!--              <el-table-column prop="returnStatus" label="退回状态"></el-table-column>-->

          <!--              <el-table-column prop="retransmissionStatus" label="重发状态"></el-table-column>-->

          <!--              <el-table-column prop="retransmissionNum" label="重发数量"></el-table-column>-->
          <!--              <el-table-column prop="qualityInspector" label="质检员"></el-table-column>-->
          <!--              <el-table-column prop="qualityTime" label="质检时间"></el-table-column>-->
          <!--              <el-table-column prop="inNum" label="入库数量"></el-table-column>-->
          <!--              <el-table-column prop="inDepot" label="入库仓库"></el-table-column>-->
          <!--              <el-table-column prop="location" label="库位"></el-table-column>-->
          <!--              <el-table-column prop="inOperateMan" label="入库操作员"></el-table-column>-->
          <!--              <el-table-column prop="inTime" label="入库时间"></el-table-column>-->
          <!--              <el-table-column prop="outNum" label="出库数量"></el-table-column>-->
          <!--              <el-table-column prop="outDepot" label="出库仓库"></el-table-column>-->
          <!--              <el-table-column prop="outOperateMan" label="出库操作员"></el-table-column>-->
          <!--              <el-table-column prop="outOperateMan" label="领用人"></el-table-column>-->
          <!--              <el-table-column prop="outTime" label="出库时间"></el-table-column>-->
          <!--              <el-table-column prop="transferNum" label="转移数量"></el-table-column>-->

          <!--            </el-table>-->
          <!--          </div>-->
        </el-row>
        <el-form-item label="备注">
          <el-input v-model="form.remark"></el-input>
        </el-form-item>
        <el-form-item label="附件名称">
          <file-upload v-model="form.fileName"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormm">生 成</el-button>
        <el-button @click="cancell">取 消</el-button>
      </div>
      <!--      物品列表-->
      <el-dialog
        width="65%"
        title="物品信息"
        :visible.sync="goodsDetailsStatus"

        append-to-body
      >
        <el-form :model="goodsQueryParams" size="small" label-width="100px">
          <el-row :gutter="10" class="mb8">
            <el-col :span="6">
              <el-form-item label="物品名称" prop="projectCode">
                <el-input
                  v-model="goodsQueryParams.name"
                  placeholder="请输入物品名称"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-button type="primary" icon="el-icon-search" size="mini" @click="goodsQuery">搜索</el-button>
            </el-col>
          </el-row>

        </el-form>

        <el-table v-loading="loading" max-height="450" :data="RyInventoryList">
          <!--      <el-table-column label="主键" align="center" prop="id" />-->
          <el-table-column label="名称" align="center" prop="name"/>
          <el-table-column label="规格" align="center" prop="specifications"/>
          <el-table-column label="wbs编码" align="center" prop="wbs"/>
          <el-table-column label="品牌" align="center" prop="brand"/>
          <el-table-column label="图片" align="center" prop="images" width="100">
            <template slot-scope="scope">
              <image-preview :src="scope.row.images" :width="50" :height="50"/>
            </template>
          </el-table-column>
          <el-table-column label="单位" align="center" prop="unit">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.ware_inventory_unit" :value="scope.row.unit"/>
            </template>
          </el-table-column>
          <el-table-column label="单价(元)" align="center" prop="unitPrice"/>
          <el-table-column label="供应商" align="center" prop="supply"/>
          <el-table-column label="库位" align="center" prop="location"/>
          <el-table-column label="操作人/经办人" align="center" prop="operator"/>
          <el-table-column label="备注" align="center" prop="remark"/>
          <el-table-column label="操作" fixed="right">
            <template slot-scope="scope">
              <el-button type="primary" @click="goodsChange(scope.row)">选中</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="goodsTotal>0"
          :total="goodsTotal"
          :page.sync="goodsQueryParams.pageNum"
          :limit.sync="goodsQueryParams.pageSize"
          @pagination="search(undefined)"
        />
      </el-dialog>
    </el-dialog>
  </div>


</template>

<script>
import {
  listRyDepotHead,
  dataprocess,
  getRyDepotHead,
  delRyDepotHead,
  addRyDepotHead,
  updateRyDepotHead
} from '@/api/purchase/ryDepotHead'
import * as XLSX from 'xlsx/xlsx.mjs'
import axios from 'axios'
import { $message } from 'element-ui'
import { getToken } from '@/utils/auth'
import { blobValidate } from '@/utils/ruoyi'
import print from 'print-js'
import * as FileSaver from 'file-saver'
import { listRyInventory } from '@/api/inventory/RyInventory'
import Cookies from 'js-cookie'
import request from '@/utils/request'
import { updatePurchaseOrder } from '@/api/purchase/purchaseOrder'
import { formatDatee } from '@/utils'

export default {

  name: 'RyDepotHead',
  dicts: ['project_status', 'purchase_status', 'return_status', 'shipping_status', 'retransmission_status'],
  data() {
    return {
      ip: 'http://localhost:8080',
      count: 0,
      uploadData: [], //文件数据
      fileData: '', // 保存选择的文件
      fileNames: [], // 上传的文件名
      list: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      ids1: '',
      // 选中的项目名
      projectName: [],
      projectName1: '',
      // 选中的项目状态
      status: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 单据主表表格数据
      ryDepotHeadList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 上传文件列表弹窗控制
      visible: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        projectCode: null,
        number: null,
        status: null,
        projectStatus: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        projectName: [
          { required: true, message: '请输入项目名', trigger: 'blur' }
        ],
        projectCode: [
          { required: true, message: '请输入项目代号', trigger: 'blur' }
        ]
      },
      ruless: {
        contractNumber: [
          { required: true, message: '请输入采购合同编号', trigger: 'blur' }
        ],
        organId: [
          { required: true, message: '请输入供应商', trigger: 'change' }
        ]
      },
      tableData: [],
      details: false,
      goodsDetailsStatus: false,
      RyInventoryList: [],
      goodsTotal: 0,
      goodsQueryParams: {
        pageNum: 1,
        pageSize: 5,
        name: null,
        projectCode: null,
        number: null,
        status: null,
        projectStatus: null
      },
      // 生成采购单弹窗控制
      purchase: false,
      // 供应商下拉框
      organOptions: [],
      linkHeadOptions: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询单据主表列表 */
    getList() {
      this.loading = true
      listRyDepotHead(this.queryParams).then(response => {
        this.ryDepotHeadList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 取消按钮
    cancell() {
      this.purchase = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectName: null,
        projectCode: null,
        type: null,
        subType: null,
        defaultNumber: null,
        number: null,
        createTime: null,
        operTime: null,
        organId: null,
        billType: null,
        remark: null,
        fileName: null,
        salesMan: null,
        status: null,
        projectStatus: null,
        linkNumber: null,
        tenantId: null,
        delFlag: null,
        tableData: []

      }
      this.fileNames = []
      this.tableData = []
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.projectName = selection.map(item => item.projectName)
      this.status = selection.map(item => item.projectStatus)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.list = []
      this.open = true
      this.form.number = 'WBSP' + formatDatee()
      this.form.createTime = new Date()
      console.log(this.form.createTime)
      this.title = '添加单据主表'
    },
    // 生成采购点单按钮操作
    producePurchase(row) {
      console.log(this.status)
      let that = this
      this.reset()
      console.log(this.ids[0])
      console.log(this.projectName[0])
      const id = row.id || this.ids[0]
      // 用来回显项目名
      that.projectName1 = row.projectName || this.projectName[0]
      that.ids1 = id
      return request({
        url: '/purchase/ryDepotDetail/selectDetailForOrder',
        method: 'get',
        params: { linkHeadId: id, organId: '' }
      }).then(function(res) {
        console.log(res)
        if (res.code === 200) {
          that.purchase = true
          that.form.projectName = that.projectName1
          that.form.number = 'CGDD' + formatDatee()
          that.tableData = res.data
          that.getOptions()
        }
      })
      // let that =this
      // this.reset();
      // const id = row.id || this.ids
      // return request({
      //   url: '/purchase/ryDepotHead/selectByDepotId/' + id,
      //   method: 'get'
      // }).then(function(res) {
      //   console.log(res)
      // })
    },
    // 详情按钮
    handleDetails(row) {
      let that = this
      return request({
        url: '/purchase/ryDepotHead/selectByDepotId/' + row.id,
        method: 'get'
      }).then(function(res) {
        console.log(res)
        if (res.code === 200) {
          that.details = true
          that.title = '单据主表详情'
          that.form = res.data
          that.tableData = res.data.tableData

        } else {
          console.log('报错了')
          that.$message({
            showClose: true,
            message: res.msg,
            duration: 0,
            type: 'warning'
          })
        }
      })
    },
    /** 提交按钮 */
    submitForm() {
      let that = this
      this.form.tableData = this.tableData
      console.log(this.form)
      this.$refs['form'].validate(valid => {
        if (valid) {
          // 修改提交
          if (this.form.id != null) {
            return request({
              url: '/purchase/ryDepotHead/editDepotHeadAndDetail',
              method: 'post',
              data: this.form
            }).then(function(res) {
              console.log(res)
              if (res.code === 200) {
                that.$message({
                  showClose: true,
                  message: '修改成功',
                  type: 'success'
                })
                that.open = false
                that.getList()
              } else {
                console.log('报错了')
                that.$message({
                  showClose: true,
                  message: res.msg,
                  duration: 0,
                  type: 'warning'
                })
              }
            }).catch(res => {
              console.log(res)
            })

            // 新增提交
          } else {
            return request({
              url: '/purchase/ryDepotHead/addDepotHeadAndDetail',
              method: 'post',
              data: this.form
            }).then(function(res) {
              console.log(res)
              if (res.code === 200) {
                that.$message({
                  showClose: true,
                  message: '新增成功',
                  type: 'success'
                })
                that.open = false
                that.getList()
              } else {
                console.log('报错了')
                that.$message({
                  showClose: true,
                  message: res.msg,
                  duration: 0,
                  type: 'warning'
                })
              }
            }).catch(res => {
              console.log(res)
            })

          }
        }
      })
    },
    // 生成采购单提交
    submitFormm() {
      let that = this
      this.form.tableData = this.tableData
      this.form.linkHeadId = this.ids1
      this.$refs['form'].validate(valid => {
        if (valid) {
          return request({
            url: '/purchase/purchaseOrder/addDepotHeadAndDetail',
            method: 'post',
            data: this.form
          }).then(function(res) {
            console.log(res)
            if (res.code === 200) {
              that.$message({
                showClose: true,
                message: '新增成功',
                type: 'success'
              })
              that.purchase = false
              that.getList()
            } else {
              console.log('报错了')
              that.$message({
                showClose: true,
                message: res.msg,
                duration: 0,
                type: 'warning'
              })
            }
          }).catch(res => {
            console.log(res)
          })
        }

      })
    },
    //修改按钮
    handleUpdate(row) {
      let that = this
      console.log(row.projectStatus)
      if (row.projectStatus === '1') {
        that.$message({
          showClose: true,
          message: '项目已结束',
          type: 'warning'
        })
      } else {
        this.reset()
        const id = row.id || this.ids
        return request({
          url: '/purchase/ryDepotHead/selectByDepotId/' + id,
          method: 'get'
        }).then(function(res) {
          console.log(res)
          if (res.code === 200) {
            that.open = true
            that.title = '修改单据主表'
            that.form = res.data
            that.tableData = res.data.tableData

          } else {
            console.log('报错了')
            that.$message({
              showClose: true,
              message: res.msg,
              duration: 0,
              type: 'warning'
            })
          }
        })
      }
    },
    // 解析excel文件
    readExcel(files) {
      this.count += 1
      if (this.count % 3 === 1) {
        console.log('===========================')
        console.log(files.file.name)
        this.fileNames.push({ name: files.file.name })
        this.fileData = files // 保存当前选择文件
        let that = this
        // console.log(files.file.originFileObj)
        let type = files.file.name.split('.')
        if (!files) {
          //如果没有文件
          return false
        } else if (type[type.length - 1] !== 'xlsx' && type[type.length - 1] !== 'xls' && type[type.length - 1] !== 'et') {
          this.$message.error('上传格式不正确，请上传xls或者xlsx格式')
          return false
        }
        const fileReader = new FileReader()
        // 如果为原生 input 则应是 files[0]
        fileReader.readAsBinaryString(files.file.originFileObj)
        fileReader.onload = ev => {// 异步执行
          try {
            const data = ev.target.result
            const workbook = XLSX.read(data, {
              type: 'binary'
            })
            const wsname = workbook.SheetNames[0] //取第一张表
            const ws = XLSX.utils.sheet_to_json(workbook.Sheets[wsname]) //生成json表格内容
            that.uploadData = [] //清空接收数据

            for (let i = 6; i < ws.length; i++) {
              let arr = {}
              //   arr.wbs = ''
              for (const key in ws[i]) {

                switch (key) {
                  case 'LIST  明 细 表':
                    arr.name = ws[i][key].toUpperCase().replace(/\s*/g, '')
                    break
                  case '__EMPTY_1':
                    arr.drawing = ws[i][key]
                    break
                  case '__EMPTY_2':
                    arr.spec = ws[i][key].toUpperCase().replace(/\s*/g, '')
                    break
                  case '__EMPTY_3':
                    arr.supplier = ws[i][key]
                    break
                  case '__EMPTY_4':
                    if (isNaN(Number(ws[i][key]))) {
                      this.$message({
                        showClose: true,
                        message: '采购数量异常',
                        duration: 3000,
                        type: 'warning'
                      })
                      ws = ''
                    } else {
                      arr.number = Number(ws[i][key])
                      break
                    }
                  case '__EMPTY_6':
                    arr.wbs = ws[i][key]
                    break
                }
              }
              if (arr.name !== undefined) {
                this.list.push(arr)
              }
            }
            console.log('===============' + this.list)
          } catch (ev) {
            console.log('报错')
            return false
          }
        }
      }

    },
    // 解析的excel文件传入后台
    generate() {
      let that = this
      console.log(that.list)
      axios({
        url: this.ip + '/infc/dataProcess',
        method: 'post',
        // responseType: 'json',
        contentType: 'application/json,charset=UTF-8 ',
        data: that.list
      }).then(function(res) {
        if (res.data.code === '001') {
          that.$message({
            showClose: true,
            message: res.data.msg,
            duration: 0,
            type: 'warning'
          })
        } else {
          res.data.data.push(that.tableData)
          for (let i = 0; i < res.data.data.length - 1; i++) {
            res.data.data[i].actualPurchaseNum = res.data.data[i].advancePurchaseNum - res.data.data[i].usableNum
            that.tableData.push(res.data.data[i])
          }
          that.list = []
          that.fileNames = []
        }
        that.visible = false
      })
    },
    //删除行
    deleteRow(data) {
      this.tableData.splice(data.$index, 1)
    },
    //增加行
    addRow() {
      let newRow = {}
      this.tableData.splice(this.tableData.length, 0, newRow)
    },
    // 获取物品信息
    search(row) {
      if (row === undefined || row.id === undefined) {
        this.goodsDetailsStatus = true
        listRyInventory(this.goodsQueryParams).then(res => {
          this.RyInventoryList = res.rows
          this.goodsTotal = res.total
          this.goodsQueryParams.name = ''
          console.log(res.rows)
        })
      }

    },
    printBox() {
      setTimeout(function() {
        print({
          printable: 'printBox',	//打印区域id
          type: 'html',		//打印类型是html
          scanStyles: false,
          targetStyles: ['*']
        })
      }, 500)
    },
    exportExcel() {
      try {
        const $e = this.$refs['report-table'].$el
        let $table = $e.querySelector('.el-table__fixed')
        if (!$table) {
          $table = $e
        }

        const wb = XLSX.utils.table_to_book($table, { raw: true })
        const wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' })
        FileSaver.saveAs(
          new Blob([wbout], { type: 'application/octet-stream' }),
          `WBS单据汇总详情.xlsx`
        )
      } catch (e) {
        if (typeof console !== 'undefined') console.error(e)
      }
    },
    updateStatus(row) {
      this.$confirm('是否确认更改项目状态?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        updateRyDepotHead(row).then(response => {
          this.$modal.msgSuccess('修改成功')
          this.getList()
        })
        // this.$message({
        //   type: 'success',
        //   message: '删除成功!'
        // });
      }).catch(() => {
        this.getList()
        // this.$message({
        //   type: 'info',
        //   message: '已取消删除'
        // });
      })

    },
    // 物品详情表格的点击事件
    goodsChange(row) {
      let boolean = true
      for (let i = 0; i < this.tableData.length; i++) {
        if (this.tableData[i].inventorySpecifications === row.specifications) {
          boolean = false
        }
      }
      let that = this
      if (boolean) {
        axios({
          url: this.ip + '/infc/getInfoByInventory',
          method: 'post',
          // responseType: 'json',
          contentType: 'application/json,charset=UTF-8 ',
          data: row
        }).then(function(res) {
          let arr = []
          for (let i = 0; i < that.tableData.length - 1; i++) {
            arr.push(that.tableData[i])
          }
          arr.push(res.data.data)
          that.tableData = arr

          that.goodsDetailsStatus = false
        })
      } else {
        that.$message({
          showClose: true,
          message: '物品已存在',
          duration: 3000,
          type: 'warning'
        })
      }

    },
    // 物品信息搜索
    goodsQuery() {
      this.goodsQueryParams.pageNum = 1
      this.search()
    },
    ab(e) {
      let that = this
      if (e !== '') {
        // console.log("linkHeadId---->"+that.form.linkHeadId);
        // //关联项目可能为空或者undefined情况;
        // // 1.当点击新增按钮并且在弹出页面中没有操作关联项目下拉框时为undefined,
        // // 2.当点击新增按钮并且在弹出页面中操作了关联项目下拉框然后清除掉的数据为''
        // if(that.form.linkHeadId === undefined || that.form.linkHeadId === ''){
        //   console.log("lll2222222");
        //   return;
        // }
        return request({
          url: '/purchase/ryDepotDetail/selectDetailForOrder',
          method: 'get',
          params: { linkHeadId: this.ids1, organId: that.form.organId }
        }).then(function(res) {
          if (res.code === 200) {
            that.tableData = res.data
          }
        })
      } else {
        return request({
          url: '/purchase/ryDepotHead/selectByDepotId/' + that.ids1,
          method: 'get'
        }).then(function(res) {
          console.log(res)
          if (res.code === 200) {
            that.tableData = res.data.tableData
          }
        })
      }
    },
    // 获取供应商下拉框信息
    getOptions() {
      let that = this
      return request({
        url: '/information/tbCustomers/CompanyTypeAll/' + 0,
        method: 'get'
      }).then(function(res) {
        that.organOptions = res.data
      })
    }

  }
}
</script>
<style scoped>
/*去除number输入框一些对于的样式*/
/deep/ .unitPrice input::-webkit-outer-spin-button,
/deep/ .unitPrice input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

/deep/ .unitPrice input[type="number"] {
  -moz-appearance: textfield;
}

</style>
